package com.zjq.authoritysystem.controller.pub;

import com.zjq.authoritysystem.common.properties.OssProperties;
import com.zjq.authoritysystem.utils.OssUtil;
import com.zjq.authoritysystem.vo.result.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author Kimiaaaaa
 * @className UploadController
 * @Description
 * @date 2023-11-08 17:10
 */
@RestController
@RequestMapping("/api/pub/oss")
public class OssController {

    @Resource
    private OssProperties ossProperties;

    @PostMapping("/upload")
    public Result upload(MultipartFile file) {
        OssUtil ossUtil = new OssUtil(ossProperties.getAccessKeyId(), ossProperties.getAccessKey(), ossProperties.getBucket(), ossProperties.getBasePath(), ossProperties.getEndpoint());
        String upload = ossUtil.upload(file);
        return Result.SUCCESS(ossProperties.getDomainName() + "/" + upload);
    }
}
